package com.itheima.website.web;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.itheima.website.domain.User;
import com.itheima.website.service.IUserService;
import com.itheima.website.utils.BeanFactory;

public class LoginServlet extends HttpServlet {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//获取已封装对象
		User user = (User) request.getSession().getAttribute("user");
		System.out.println(user);
		//获取Service层
		String path = request.getSession().getServletContext().getRealPath("WEB-INF/classes/website.xml");
		try {
			IUserService userService = (IUserService) BeanFactory.createBean("userService",path);
			userService.checkUser(user.getUsername(),user.getPassword());
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		
		
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
